package wstrader;

//import javax.servlet.*;
import javax.servlet.http.*;
//import java.io.*;
//import java.util.*;
import pc.sql.*;
//import pc.util.*;
import pc.system.*;
//import pc.sql.value.*;
//import wstrader.task.*;

public class Trader extends WServlet//HttpServlet
{
  //private static ConnectionPool connPool = null;
  //private static SQLCommand     sqlCommand = null;
  private static String db_name = null;
  public static String work_path = null;

  public Trader(String db_name)
  {
    super(db_name,"Trader");
    this.db_name = db_name;
    System.out.println("DBName:-"+db_name);
  }
  //Initialize global variables
  public void init() //throws ServletException
  {
    super.init();
    work_path  = getWorkPath();
  }

  //Process the HTTP Get request
  public void doGet(HttpServletRequest request, HttpServletResponse response) //throws ServletException, IOException
  {
    super.doGet(request, response);
    if (this.getTaskID() == taskLogon) {
      doLogon();
    }
  }

  //Process the HTTP Post request
  public void doPost(HttpServletRequest request, HttpServletResponse response) //throws ServletException, IOException
  {
    doGet(request, response);
  }

  //Clean up resources
  public void destroy()
  {
    super.destroy();
    //connPool.releaseConnections();
  }

/*
  public static SQLCommand getSQLCommand()
  {
    return Trader.sqlCommand;
  }
*/
  public static Users getUser(String uid, String language)
  {
    return (Users)getAuth(uid, language, new Users(null,null,null,language));
  }

  public static Users getUser(String uid)
  {
    return getUser(uid,null);
  }

  public static ConnectionPool getConnectionPool()
  {
    return getConnectionPool(db_name);
  }

  private void doLogon() //throws ServletException, IOException
  {
    String username = getParameter("username");
    String password = getParameter("password");
    String language = getParameter("language");
    if (language == null) language = "us";

    Users auth = new Users(getConnectionPool(),username,password,language);

    super.doLogon(auth);
  }
}
